from enum import Enum, unique

# API 基本格式定义
API_TEMPLATE = {
    "code": 200,  # 状态码 (status code)
    "msg": "ok",  # 提示信息
    "data": []  # 接口数据
}


@unique
class HttpCode(Enum):
    # 合法请求
    ok = (200, "ok")
    # 服务器错误
    internal_error = (5002, "服务器内部错误")
    # 参数错误
    parameter_error = (4001, "参数错误")
    data_error = (4002, "数据错误")
    result_empty = (4003, "数据为空")
    format_error = (4004, "格式错误")
    # 账户相关
    authentication_error = (4101, "密码错误")
    unregistered_error = (4102, "用户未开通")
    token_expired_error = (4106, "距上次登录时间太久,请重新登录")
    token_authentication_error = (4104, "认证失败")
    token_invalid_error = (4105, "非法的用户")
    user_expire_error = (4107, '用户账号已过期')
    # 自定义
    user_repeat_error = (4201, '组合名称已存在')
    event_name_repeat_error = (4202, '该情景名称已存在')
    index_name_repeat_error = (4203, '该指数创建重复')

    @classmethod
    def http_code_dict(cls):
        return {obj.value[0]: obj.value[1] for obj in list(HttpCode)}
